/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package com.aries.ui.widget.demo.slice;

 import com.aries.ui.widget.demo.ResourceTable;
 import com.aries.ui.widget.demo.base.BaseAbilitySlice;
 import com.aries.ui.widget.progress.UIProgressDialog;

 import ohos.aafwk.content.Intent;

 import ohos.agp.colors.RgbColor;
 import ohos.agp.colors.RgbPalette;
 import ohos.agp.components.Component;
 import ohos.agp.components.Switch;
 import ohos.agp.components.Text;
 import ohos.agp.components.element.ShapeElement;

public class LoadingAbilitySlice extends BaseAbilitySlice {
    private boolean isDefaultItemShape = true;
    private boolean isDefaultProgress = true;
    private boolean isDefaultBackground = true;
    private boolean isShowTitle = true;
    private Text mNomalText;
    private Switch mNomalIv;
    private Text mQQText;
    private Switch mQQIv;
    private Text mWxText;
    private Switch mWxIv;
    private Switch mProgressIv;
    private Text mProgressText;

    @Override
    protected void setTitleBar() {
        titleBar.setTitleMainText("UIProgressDialog示例").setStatusBackgroundColor(RgbPalette.WHITE.asArgbInt());
    }

    @Override
    protected void initView(Intent intent) {
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setRgbColor(RgbPalette.WHITE);
        findComponentById(ResourceTable.Id_text_nomal).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                shapeElement.setRgbColor(RgbPalette.WHITE);
                new UIProgressDialog.NormalBuilder(getAbility())
                        .setMessage(isShowTitle ? ResourceTable.String_loading : 0)
                        .setIndeterminateDrawable(isDefaultProgress ? 0 : com.aries.ui.widget.ResourceTable.Media_loading_icon)
                        .setBackgroundRadiusResource(com.aries.ui.widget.ResourceTable.String_dp_radius_loading)
                        .setBackground(shapeElement)
                        .setBackgroundRadius(isDefaultItemShape ? 20f : 0)
                        .create(isDefaultProgress ? UIProgressDialog.NOMAL : UIProgressDialog.CUSTOMIZE)
                        .setDimAmount(0f)
                        .show();
            }
        });

        findComponentById(ResourceTable.Id_text_wb).setClickedListener(component -> {
            shapeElement.setRgbColor(RgbColor.fromArgbInt(0x66000000));
            new UIProgressDialog.WeBoBuilder(getAbility())
                    .setMessage(isShowTitle ? ResourceTable.String_loading : 0)
                    .setIndeterminateDrawable(isDefaultProgress ? com.aries.ui.widget.ResourceTable.Media_img_loading_wei_bo : com.aries.ui.widget.ResourceTable.Media_loading_icon)
                    .setBackgroundRadiusResource(com.aries.ui.widget.ResourceTable.String_dp_radius_loading)
                    .setBackground(shapeElement)
                    .setBackgroundRadius(isDefaultItemShape ? 20f : 0)
                    .create(UIProgressDialog.CUSTOMIZE)
                    .show();
        });

        findComponentById(ResourceTable.Id_text_vx).setClickedListener(component -> {
            shapeElement.setRgbColor(RgbColor.fromArgbInt(0x66000000));
            new UIProgressDialog.WeChatBuilder(getAbility())
                    .setMessage(isShowTitle ? ResourceTable.String_loading : 0)
                    .setIndeterminateDrawable(isDefaultProgress ? com.aries.ui.widget.ResourceTable.Media_img_loading_we_chat : com.aries.ui.widget.ResourceTable.Media_loading_icon)
                    .setBackgroundRadiusResource(com.aries.ui.widget.ResourceTable.String_dp_radius_loading)
                    .setBackground(shapeElement)
                    .setBackgroundRadius(isDefaultItemShape ? 20f : 0)
                    .create(UIProgressDialog.CUSTOMIZE)
                    .show();
        });

        findComponentById(ResourceTable.Id_text_material).setClickedListener(component -> {
            shapeElement.setRgbColor(RgbPalette.WHITE);
            new UIProgressDialog.MaterialBuilder(getAbility())
                    .setMessage(isShowTitle ? ResourceTable.String_loading : 0)
                    .setBackgroundRadiusResource(com.aries.ui.widget.ResourceTable.String_dp_radius_loading)
                    .setBackground(shapeElement)
                    .setBackgroundRadius(isDefaultItemShape ? 20f : 0)
                    .create(UIProgressDialog.NOMAL)
                    .setDimAmount(0f)
                    .show();
        });

        mNomalText = (Text) findComponentById(ResourceTable.Id_nomal_title);
        mNomalIv = (Switch) findComponentById(ResourceTable.Id_iv_nomal_title);

        mQQText = (Text) findComponentById(ResourceTable.Id_qq_title);
        mQQIv = (Switch) findComponentById(ResourceTable.Id_iv_qq_title);

        mWxText = (Text) findComponentById(ResourceTable.Id_wx_title);
        mWxIv = (Switch) findComponentById(ResourceTable.Id_iv_wx_title);
        mProgressText = (Text) findComponentById(ResourceTable.Id_progress_title);
        mProgressIv = (Switch) findComponentById(ResourceTable.Id_iv_progress);

        mNomalIv.setChecked(true);
        mNomalIv.setCheckedStateChangedListener((absButton, isChecked) -> {
            isShowTitle = isChecked;
            mNomalText.setText(isShowTitle ? "显示Message" : "隐藏Message");
        });

        mQQIv.setChecked(true);
        mQQIv.setCheckedStateChangedListener((absButton, isChecked) -> {
            isDefaultItemShape = isChecked;
            mQQText.setText(isDefaultItemShape ? "背景圆角" : "背景直角");
        });

        mWxIv.setChecked(true);
        mWxIv.setCheckedStateChangedListener((absButton, isChecked) -> {
            isDefaultBackground = isChecked;
            mWxText.setText(isDefaultBackground ? "默认View背景" : "自定义View背景");
        });

        mProgressIv.setChecked(true);
        mProgressIv.setCheckedStateChangedListener((absButton, isChecked) -> {
            isDefaultProgress = isChecked;
            mProgressText.setText(isDefaultProgress ? "默认Progress" : "自定义Progress");
        });
    }

    @Override
    protected int getLayout() {
        return ResourceTable.Layout_loading_ability_alert;
    }
//    @Override
//    public void onStart(Intent intent) {
//        super.onStart(intent);
//        super.setUIContent(ResourceTable.Layout_loading_ability_alert);
//        ShapeElement shapeElement = new ShapeElement();
//        shapeElement.setRgbColor(RgbPalette.WHITE);
//        findComponentById(ResourceTable.Id_text_nomal).setClickedListener(new Component.ClickedListener() {
//            @Override
//            public void onClick(Component component) {
//                new UIProgressDialog.MaterialBuilder(getAbility())
//                        .setMessage(isShowTitle ? ResourceTable.String_loading : 0)
////                        .setIndeterminateDrawable(com.aries.ui.widget.ResourceTable.Media_img_loading_we_chat )
//                        .setBackgroundRadius(isDefaultTitleColor ? 0 : 20f)
//                        .setBackground(shapeElement)
//                        .create()
//                        .setDimAmount(100f)
//                        .show();
//
////                new UIProgressDialog.NormalBuilder(getAbility())
////                        .setMessage("6656")
//////                        .setIndeterminateDrawable(com.aries.ui.widget.ResourceTable.Media_img_loading_we_chat )
////                        .setBackgroundRadiusResource(com.aries.ui.widget.ResourceTable.String_dp_radius_loading)
////                        .create()
////                        .setDimAmount(0f)
////                        .show();
//
////                new UIProgressDialog.WeBoBuilder(getAbility())
////                        .setMessage("0544545")
////                        .setIndeterminateDrawable(com.aries.ui.widget.ResourceTable.Media_img_loading_we_chat)
////                        .setBackgroundRadiusResource(com.aries.ui.widget.ResourceTable.String_dp_radius_loading)
////                        .setBackground(shapeElement)
////                        .create()
////                        .setDimAmount(0f)
////                        .isShowOrHide(false)
////                        .show();
//            }
//        });
//        findComponentById(ResourceTable.Id_sBtn_nomal).setClickedListener(this);
//        findComponentById(ResourceTable.Id_sBtn_qq).setClickedListener(this);
//        findComponentById(ResourceTable.Id_sBtn_wx).setClickedListener(this);
//        mNomalText = (Text) findComponentById(ResourceTable.Id_nomal_title);
//        mNomalIv = (Image) findComponentById(ResourceTable.Id_iv_nomal_title);
//
//        mQQText = (Text) findComponentById(ResourceTable.Id_qq_title);
//        mQQIv = (Image) findComponentById(ResourceTable.Id_iv_qq_title);
//
//        mWxText = (Text) findComponentById(ResourceTable.Id_wx_title);
//        mWxIv = (Image) findComponentById(ResourceTable.Id_iv_wx_title);
//
//
//    }
//    private void handleFunction3() {
//        isDefaultBackground = !isDefaultBackground;
//        mWxIv.setPixelMap(isDefaultBackground ? ResourceTable.Media_switch_on : ResourceTable.Media_switch_off);
//        mWxText.setText(isDefaultBackground ? "默认View背景" : "自定义View背景");
//    }
//
//    private void handleFunction4() {
//        isDefaultProgress = !isDefaultProgress;
//        mProgressIv.setPixelMap(isDefaultProgress ? ResourceTable.Media_switch_on : ResourceTable.Media_switch_off);
//        mProgressText.setText(isDefaultProgress ? "默认Progress" : "自定义Progress");
//    }
//
//
//    private void handleunction2() {
//        isDefaultItemShape = !isDefaultItemShape;
//        mQQIv.setPixelMap(isDefaultItemShape ? ResourceTable.Media_switch_on : ResourceTable.Media_switch_off);
//        mQQText.setText(isDefaultItemShape ? "背景圆角" : "背景直角");
//    }
//
//    private void handleFunction1() {
//        isShowTitle = !isShowTitle;
//        mNomalIv.setPixelMap(isShowTitle ? ResourceTable.Media_switch_on : ResourceTable.Media_switch_off);
//        mNomalText.setText(isShowTitle ? "显示Message" : "隐藏Message");
//    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
